﻿using B.S.DataBase.MyProject.Domain.BOM;
using B.S.DataBase.MyProject.Domain.procedure;
using B.S.DataBase.MyProject.Domain.productionworkorder;
using B.S.DataBase.MyProject.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using T.E.ERP.Read.API.Applicantions.Command.BomCOmmand;
using T.E.ERP.Read.API.Applicantions.Command.GetrovalCommand;
using T.E.ERP.Read.API.Applicantions.Command.SCWorkOrderCommand;
using T.E.ERP.Read.API.Dtos.Dtos;

namespace T.E.ERP.Read.API.Controllers
{
    /// <summary>
    /// 工单管理控制器-读
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class WorkOrderController : ControllerBase
    {
        /// <summary>
        /// 中介者
        /// </summary>
        private readonly IMediator mediator;
        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="mediator"></param>
        public WorkOrderController(IMediator mediator)
        {
            this.mediator = mediator;
        }



        #region 生产工单
        /// <summary>
        /// 查询生产工单单号
        /// 物联网-智能MES生产管理系统-09-生产工单管理V1.1-20250206
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<List<AssociatedProductionOrder>>> GetSCDanHao([FromQuery] SCDanHaoQuerycommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 查询生产工单的工艺路线
        /// 物联网-智能MES生产管理系统-09-生产工单管理V1.1-20250206
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<List<ProcessRoute>>> GetSCLuXian([FromQuery] SCLXQueryCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        ///查询生产工单的物品名称列表
        ///物联网-智能MES生产管理系统-09-生产工单管理V1.1-20250206
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<List<item_classification_detail>>> GetWuPinname([FromQuery]SCWuPinQueryCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 查询生产工单列表
        /// 物联网-智能MES生产管理系统-09-生产工单管理V1.1-20250206
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<List<SCWorkOrderDtos>>> GetSCWorkOrder([FromQuery] SCWorkOrderQueryCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 查询生产工单详情列表
        /// 物联网-智能MES生产管理系统-09-生产工单管理V1.1-20250206
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<List<SCWorkOrderXQDtos>>> GetSCWorkOrderXQ([FromQuery] SCWorkOrderXQQueryCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 查询生产工单的工序流程（报工记录）
        /// 物联网-智能MES生产管理系统-09-生产工单管理V1.1-20250206
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<List<ProcessFlowSheet>>> GetSCWorkOrderLC([FromQuery] SCLCQueryCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 查询生产工单的操作记录
        /// 物联网-智能MES生产管理系统-09-生产工单管理V1.1-20250206
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<List<CaoZuoJiLu>>> GetSCWorkOrderJL([FromQuery]SCJLQueryCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }


        #endregion

        #region BOM工单
       /// <summary>
       /// 查询Bom工单全部信息
       /// 物联网-智能MES生产管理系统-01-BOM管理V1.1-20250206
       /// </summary>
       /// <param name="request">请求</param>
       /// <returns>返回列表</returns>
       [HttpGet]
        public async Task<APIResult<List<BomInfo>>> GetBomAll([FromQuery]GetBomCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 查询Bom详细信息
        /// 物联网-智能MES生产管理系统-01-BOM管理V1.1-20250206
        /// </summary>
        /// <param name="request">请求</param>
        /// <returns>返回任务</returns>
        [HttpGet]
        public async Task<APIResult<List<BomDTO>>> ReverseBom([FromQuery] ReverseBomCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 查询物料
        /// 物联网-智能MES生产管理系统-01-BOM管理V1.1-20250206
        /// </summary>
        /// <param name="request">请求</param>
        /// <returns>返回列表</returns>
        [HttpGet]
        public async Task<APIResult<List<BomParts>>> GetBomPart([FromQuery] GetBomPartsCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 查询工序
        /// 物联网-智能MES生产管理系统-01-BOM管理V1.1-20250206
        /// </summary>
        /// <param name="request">请求</param>
        /// <returns>返回列表</returns>
        [HttpGet]
        public async Task<APIResult<List<ProcessInfo>>> GetProcess([FromQuery] GetProcessInfoCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 查询操作记录
        /// 物联网-智能MES生产管理系统-01-BOM管理V1.1-20250206
        /// </summary>
        /// <param name="request">请求</param>
        /// <returns>返回列表</returns>
        [HttpGet]
        public async Task<APIResult<List<OperationRecord>>> GetOperationRecord([FromQuery]GetOperationRecordCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 反填Bom单表信息
        /// 物联网-智能MES生产管理系统-01-BOM管理V1.1-20250206
        /// </summary>
        /// <param name="request">请求</param>
        /// <returns>返回列表</returns>
        [HttpGet]
        public async Task<APIResult<List<BomInfo>>> GetOneBom([FromQuery] GetReverBomCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 反填工艺流程
        /// 物联网-智能MES生产管理系统-01-BOM管理V1.1-20250206
        /// </summary>
        /// <param name="request">请求</param>
        /// <returns>返回列表</returns>
        [HttpGet]
        public async Task<APIResult<ProcessInfo>> ReGetProcessInfoById([FromQuery] ReGetProcessCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
        #endregion

        #region 审批管理
        /// <summary>
        /// 审批管理列表
        /// 物联网-智能MES生产管理系统-08-审批管理V1.1-20250206
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<List<ApprovalTrail>>> GetApproval()
        {
            try
            {
                return await mediator.Send(new GetvalCommd());
            }
            catch (Exception)
            {

                throw;
            }
        }

        #endregion
    }
}
